package 单例模式;

public class 双重校验锁 {

    private volatile static 双重校验锁 instance;

    private 双重校验锁(){}

    public static 双重校验锁 getInstance(){
        if(instance == null){//读
            synchronized (双重校验锁.class) {//使用同一个对象，保证多线程同步互斥
                if(instance == null) {
                    instance = new 双重校验锁();//写
                }
            }
        }
        return instance;//读
    }
}